package com.cardone.platform.authority.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.context.Contexts;
import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.authority.dto.PeVaRuTransactModeDto;
import com.cardone.platform.authority.service.PeVaRuTransactModeService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 许可、验证规则与处理模式
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/authority/peVaRuTransactMode/")
@Controller
public class PeVaRuTransactModeController {

	/**
	 * 许可、验证规则与处理模式：删除
	 * 
	 * @param deletePeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
  public Callable<ReturnDataDto<String>> deleteJson(final PeVaRuTransactModeDto deletePeVaRuTransactMode) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(PeVaRuTransactModeService.class).deleteByIds(deletePeVaRuTransactMode);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 许可、验证规则与处理模式：编辑
	 * 
	 * @param findPeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<PeVaRuTransactModeDto>> findByIdJson(final PeVaRuTransactModeDto findPeVaRuTransactMode, final Model model) {
		return new Callable<ReturnDataDto<PeVaRuTransactModeDto>>() {
			@Override
			public ReturnDataDto<PeVaRuTransactModeDto> call() throws Exception {
				try {
					final PeVaRuTransactModeDto peVaRuTransactMode = ContextHolder.getBean(PeVaRuTransactModeService.class).findById(PeVaRuTransactModeDto.class, findPeVaRuTransactMode);

					return ReturnDataUtils.newReturnData(peVaRuTransactMode);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, PeVaRuTransactModeController.log);
				}
			}
		};
	}

	/**
	 * 许可、验证规则与处理模式：分页查询
	 * 
	 * @param paginationPeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
  public Callable<ReturnDataDto<PaginationDto<PeVaRuTransactModeDto>>> paginationByLikeCodeJson(final PeVaRuTransactModeDto paginationPeVaRuTransactMode) {
		return new Callable<ReturnDataDto<PaginationDto<PeVaRuTransactModeDto>>>() {
			public ReturnDataDto<PaginationDto<PeVaRuTransactModeDto>> call() throws Exception {
				try {
					final PaginationDto<PeVaRuTransactModeDto> peVaRuTransactModePagination = ContextHolder.getBean(PeVaRuTransactModeService.class).paginationByLikeCode(PeVaRuTransactModeDto.class, paginationPeVaRuTransactMode);
				
					return ReturnDataUtils.newReturnData(peVaRuTransactModePagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 许可、验证规则与处理模式：分页查询
	 * 
	 * @param paginationPeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
  public void paginationHtml(final PeVaRuTransactModeDto paginationPeVaRuTransactMode, final Model model) {
		final PaginationDto<PeVaRuTransactModeDto> peVaRuTransactModePagination = ContextHolder.getBean(PeVaRuTransactModeService.class).paginationByLikeCode(PeVaRuTransactModeDto.class, paginationPeVaRuTransactMode);
		
		model.addAttribute("peVaRuTransactModePagination", peVaRuTransactModePagination);
	}
	
	/**
	 * 许可、验证规则与处理模式：分页查询
	 * 
	 * @param findPeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
  public void editHtml(final PeVaRuTransactModeDto findPeVaRuTransactMode, final Model model) {
		final PeVaRuTransactModeDto peVaRuTransactMode = ContextHolder.getBean(PeVaRuTransactModeService.class).findById(PeVaRuTransactModeDto.class, findPeVaRuTransactMode);
		
		model.addAttribute("peVaRuTransactMode", peVaRuTransactMode);
	}

	/**
	 * 许可、验证规则与处理模式：查询
	 * 
	 * @param findListPeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @return 许可、验证规则与处理模式对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
  	public Callable<ReturnDataDto<List<PeVaRuTransactModeDto>>> findListByLikeCodeJson(final PeVaRuTransactModeDto findListPeVaRuTransactMode) {
		return new Callable<ReturnDataDto<List<PeVaRuTransactModeDto>>>() {
			public ReturnDataDto<List<PeVaRuTransactModeDto>> call() throws Exception {
				try {
					final List<PeVaRuTransactModeDto> peVaRuTransactModeList = ContextHolder.getBean(PeVaRuTransactModeService.class).findListByLikeCode(PeVaRuTransactModeDto.class, findListPeVaRuTransactMode);
				
					return ReturnDataUtils.newReturnData(peVaRuTransactModeList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 许可、验证规则与处理模式：保存
	 * 
	 * @param savePeVaRuTransactMode
	 *            许可、验证规则与处理模式对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
  public Callable<ReturnDataDto<String>> saveJson(final PeVaRuTransactModeDto savePeVaRuTransactMode) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(PeVaRuTransactModeService.class).saveByIdOrCode(PeVaRuTransactModeDto.class, savePeVaRuTransactMode);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}
}
